<?php
namespace MobileHome\Controller;

class CommonController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取地区列表
     * 接口名称：zhongan.cargo.getAllCargoArea
     */
    public function getAllCargoAreaAction()
    {
        $serviceName = "zhongan.cargo.getAllCargoArea";
        $params = ['test' => 1]; //因为对方的接口没有值的话,会报json解析错误
        $version = C('ZONGAN.common_version');
        $response = $this->getZaCommonDatas($serviceName, $params, $version);
        if (200 != $response['coce']) {
            $this->json(4001, sprintf('获取地区列表失败, 失败原因[code:%s|message:%s])', $response['code'], $response['message']));
        }
        $this->json(200, 'SUCCESS', $response['datas']);
    }

    public function testAction()
    {
        require_once __DIR__ . '/ZhongAn/ZaCommon/common/ZhongAnApiClient.php';


        // TODO 指定环境 iTest:测试环境; uat:预发环境; prd:生产环境
        $_env = "uat";

        // TODO 开发者的appKey，由众安提供
        $_appKey = "d7ba23de065aac3479e86dd0bcd51f90";
        // d7ba23de065aac3479e86dd0bcd51f90 uat
        // 3ee877531b114794eb18bbcff859c482 iTest

        // TODO 开发者的私钥，由开发者通过openssl工具生成，不需要PKCS8转码
        $_privateKey = "-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQD23llSmXxQlEZSRyQID9sJXIqX4XNjoeoU2GWlc+B2XqwBvqL1
Jg9bGuJl//Miw9JyrE9SnOBfxGaBIz80RqD7GDuc+a7M8OsZYELZJ5SuhwcdBozb
xMj63E0QxhGdeeSfDKDY9QatZ54dkPM57l4uNrLB9/fI2y3AgKreIeJ4ZQIDAQAB
AoGBALY21i1OluCPIPyX//NnaKAXS0Dhqp7uou2x8AzYY+Ra6pD7GiLibdEsHdF1
wwt1CH+VyZLLsh1dxN8qmftG6ogYaUxqajem8zbilWev0R0eViPbsEVssm3V7i6b
OygPFCMIsgD2EbP8zXOZ1DIZTX6rnbLrR62vLAofSR+/PA/dAkEA/15RIG3k8yEC
Fct0KB2U5XSwVEc4N75Dbdk5//ct0HREFHpwGf7bnn6wqo9o54RlJlp3JVTqMs+C
HymlJDZ1AwJBAPd6poLQAzFDG9k6OyVdIbBUoF7S5IH3TqN25nqbGqbhuBo+A8C6
5EIQMpQOB7rMbZJRz9DsdUZU2TPlLSfXXHcCQQDV5rvPjR18ZYaomN24CGdC98YH
Igy97HnwlkcV14ahl/G6sYAa1jZBgV8bzroRSv2q7ZXlSEZPvy8ASVLRjWffAkEA
vt7X4fhxHeN2bRoeV/j2bLs4XSoml56YBjdEF7fc3G0mwwalelYqilFX0RzpFUdq
EvoKYEafRLlYNFBDfYD6jQJBANS/jvYBZPcaQUR8Gs69jp+Wr6hOm6pk6BF0hz/h
Y6BbAVoysred7QzIOH6flqaESf8jM6Cxh9u/FdGD15/mPKY=
-----END RSA PRIVATE KEY-----";

        // TODO 指定服务名，由众安提供
        $_serviceName = "zhongan.user.person.addByIdentityNo";

        // TODO 业务参数，字段信息参照接口文档
        $_params = array (
            "userName" => "肖建强",
            "identityNo" => "362426198910198411"
        );

        $_client = new \ZhongAnApiClient ( $_env, $_appKey, $_privateKey, $_serviceName );

        $_response = $_client->call ( $_params );
        var_dump ( $_response ["bizContent"] );

    }

    public function applyAction()
    {
        $serviceName = "zhongan.cargo.common.applyValidateByCar";
        $_params = [
            'channelOrderNo' => '11111', //渠道订单号，唯一不可重复
            'channelId' => '1968', //渠道ID,固定值，由众安指定并提供
            'productNo' => '1416c49773a6a0980e5f00943756b31377ea701f4c6b', //产品ID,固定值，由众安指定并提供
            'coverage' => '100', //保额
            'holderName' => '王乐乐', //投保人名称
            'holderCertType' => 'TY', //投保人证件类型（TY：统一社会信用代码, Z：组织机构代码证; 默认TY）
            'holderCertNo' => '410602198903214511', //投保人证件号码
            'holderEmail' => '291518@qq.com',
            'holderTel' => '18116456783',
            'insureName' => '小鱼儿', //被保险人名称
            'insureCertType' => 'TY', //被保险人证件类型（TY：统一社会信用代码, Z：组织机构代码证; 默认TY）
            'insureCertNo' => '410602198703214511', //被保险人证件号码
            'transNo' => 'F2345', //车辆牌照号
            'trailerNo' => '挂34345', //挂车车牌号(5-10个字符，需包含‘挂’字)
            'freightNo' => '342435353536', //发票号/提单号/运单号
            'expectStartTime' => date('Y-m-d H:i:s'), //起运日期
            'departurePlace' => '', //起运地(按照国标：由众安提供)
            'destinationPlace' => '', //目的地(按照国标：由众安提供)
            'isShowPremium' => '', //是否显示费率及保费(即在电子保单中是否展示费率及保费)
            'compensationLimit' => '100万', //责任限额(取值范围：100万、150万、200万、250万、300万)
            'einvoice' => 'Y', //电子发票标识(Y：索要电子发票, N：不索要电子发票)
            'taxpayerRegNum' => '23423455', //纳税人识别号( 如果einvoice为Y，并且投保人为公司，taxpayerRegNum则必)
            'createTime' => date('Y-m-d H:i:s'),
            'updateTime' => date('Y-m-d H:i:s'),
        ];
        $params['param'] = $_params;
        $version = C('ZONGAN.applyValidateByCar_version');
        $response = $this->getZaCommonDatas($serviceName, $params, $version);
        var_dump($response ["bizContent"]);
    }

}